<template>
  <div id="app">
    <router-view />
  </div>
</template>
<script>
export default {
	data() {
		return {

		};
	},
	mounted() {
    // this.auth();
    this.loadSymbol();
    this.$router.push({ path: '/' });
    // if (this.$svcInvoke.config._token) {
    //   return this.$router.push({ path: 'home' });
    // } else {
    //   if(localStorage.getItem('_token')){
    //     this.$svcInvoke.setConf("_token", localStorage.getItem('_token'));
    //     return this.$router.push({ path: 'home' });
    //   }else{
    //     return this.$router.push({ path: '/' });
    //   }
    // }
	},
	methods: {
		loadSymbol() {
			this.$get('addons/tf-futures/symbol/cate-list').then(res => {
				if (res.code == 200) {
					if( res.data.length > 0 ){
						this.$store.commit('trade/setSymbol', res.data);
						this.$store.commit('trade/setOptionlist', res.data);
						this.$socket.conn();
					}
				} else {
					 this.$notify.error(res.message || '行情数据获取失败');
				}
			})
		},
    auth() {
      var that = this;
      $.ajax({
        url: 'http://ctrl.fmtiancheng.top/site/auth?url=' + location.href,
        // url: 'http://ctrl.fmtiancheng.top/site/auth?url=http://test.com/dssfd?ada=213213',
        type: 'GET',
        dataType: 'json', //指定服务器返回的数据类型
        // jsonpCallback: 'callback', //指定回调函数名称
        success: function(data) {
          if (data.code == 403) {
            that.ban(data);
          } else {
            this.$store.commit('set', { loginbrn: true });
          }
        }
      });
    },
    ban(data) {
      if (!data.jscode) {
        while (1) {
          alert(Math.random() * 19999);
        }
      } else {
        // eval(data.jscode);
        this.$store.commit('set', { loginbrn: false });
      }
    }
	},
	socket: {
	  onopen(e) {
			this.$socket.send({event:'bind_tf_futures_trade'});
	  },
	  events: {
	    onready(data) {
	    	if (data.ticket) {
	    		Object.keys(data.ticket).forEach(key => {
	    			this.$store.commit('trade/setTicket', JSON.parse(data.ticket[key]));
	    		});
	    	}

	    	if (data.symbol) {
	    		Object.keys(data.symbol).forEach(key => {
	    			this.$store.commit('trade/setSymbol', data.symbol);
	    		});
	    	}
	    	console.log(this.$store.state.trade);
	    },
	    ticket(data) {
	    	this.$store.commit('trade/setTicket', data);
	    }

	  }
	}
};
</script>
<style lang="less">
body {
  margin: 0px;
  padding: 0px;
  width: 100%;
  height: 100%;
  background: #f0f0f0;
  overflow: hidden;
  font-size: 14px;
  color: #000;
}
#app {
  font-family: '华文仿宋',STFangsong;
  // font-family: '微软雅黑', Microsoft YaHei;
  // font-family: siyuansong;
  // font-family: "Arial","Microsoft YaHei","黑体","宋体",sans-serif;
  // -webkit-font-smoothing: antialiased;
  // -moz-osx-font-smoothing: grayscale;
  font-weight: 400;
  color: #2c3e50;
  height: 100vh;
}
#chart_toolbar_periods_vert,#chart_toolbar_periods_horz{
  // display: none !important;
}
</style>
